home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / samples / docbook / xsl / html / glossary.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-09  |  9.9 KB  |  320 lines  |  [□□□□/□□□□]

  1. glossary.xsl%Kπ¢tÚπ¢tÚÅÅAƒ<?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 version='1.0'>
  4.  
  5. <!-- ********************************************************************
  6.      $Id: glossary.xsl,v 1.1 2002/05/29 09:55:49 dan Exp $
  7.      ********************************************************************
  8.  
  9.      This file is part of the XSL DocBook Stylesheet distribution.
  10.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  11.      and other information.
  12.  
  13.      ******************************************************************** -->
  14.  
  15. <!-- ==================================================================== -->
  16.  
  17. <xsl:template match="glossary">
  18.   <div class="{name(.)}">
  19.     <xsl:if test="$generate.id.attributes != 0">
  20.       <xsl:attribute name="id">
  21.         <xsl:call-template name="object.id"/>
  22.       </xsl:attribute>
  23.     </xsl:if>
  24.  
  25.     <xsl:call-template name="glossary.titlepage"/>
  26.  
  27.     <xsl:choose>
  28.       <xsl:when test="glossdiv">
  29.         <xsl:apply-templates select="(glossdiv[1]/preceding-sibling::*)"/>
  30.       </xsl:when>
  31.       <xsl:otherwise>
  32.         <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  33.       </xsl:otherwise>
  34.     </xsl:choose>
  35.  
  36.     <xsl:choose>
  37.       <xsl:when test="glossdiv">
  38.         <xsl:apply-templates select="glossdiv"/>
  39.       </xsl:when>
  40.       <xsl:otherwise>
  41.         <dl>
  42.           <xsl:apply-templates select="glossentry"/>
  43.         </dl>
  44.       </xsl:otherwise>
  45.     </xsl:choose>
  46.  
  47.     <xsl:call-template name="process.footnotes"/>
  48.   </div>
  49. </xsl:template>
  50.  
  51. <xsl:template match="glossary/glossaryinfo"></xsl:template>
  52. <xsl:template match="glossary/title"></xsl:template>
  53. <xsl:template match="glossary/subtitle"></xsl:template>
  54. <xsl:template match="glossary/titleabbrev"></xsl:template>
  55.  
  56. <xsl:template match="glossary/title" mode="component.title.mode">
  57.   <h2>
  58.     <xsl:apply-templates/>
  59.   </h2>
  60. </xsl:template>
  61.  
  62. <xsl:template match="glossary/subtitle" mode="component.title.mode">
  63.   <h3>
  64.     <i><xsl:apply-templates/></i>
  65.   </h3>
  66. </xsl:template>
  67.  
  68. <!-- ==================================================================== -->
  69.  
  70. <xsl:template match="glosslist">
  71.   <div class="{name(.)}">
  72.     <xsl:call-template name="anchor"/>
  73.     <dl>
  74.       <xsl:apply-templates/>
  75.     </dl>
  76.   </div>
  77. </xsl:template>
  78.  
  79. <!-- ==================================================================== -->
  80.  
  81. <xsl:template match="glossdiv">
  82.   <div class="{name(.)}">
  83.     <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  84.  
  85.     <dl>
  86.       <xsl:apply-templates select="glossentry"/>
  87.     </dl>
  88.   </div>
  89. </xsl:template>
  90.  
  91. <xsl:template match="glossdiv/title">
  92.   <h3 class="{name(.)}">
  93.     <xsl:apply-templates/>
  94.   </h3>
  95. </xsl:template>
  96.  
  97. <!-- ==================================================================== -->
  98.  
  99. <!--
  100. GlossEntry ::=
  101.   GlossTerm, Acronym?, Abbrev?,
  102.   (IndexTerm)*,
  103.   RevHistory?,
  104.   (GlossSee | GlossDef+)
  105. -->
  106.  
  107. <xsl:template match="glossentry">
  108.   <xsl:apply-templates/>
  109. </xsl:template>
  110.  
  111. <xsl:template match="glossentry/glossterm">
  112.   <dt>
  113.     <xsl:apply-templates/>
  114.   </dt>
  115. </xsl:template>
  116.  
  117. <xsl:template match="glossentry/glossterm[1]" priority="2">
  118.   <dt>
  119.     <xsl:call-template name="anchor">
  120.       <xsl:with-param name="node" select=".."/>
  121.       <xsl:with-param name="conditional">
  122.         <xsl:choose>
  123.           <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
  124.           <xsl:otherwise>1</xsl:otherwise>
  125.         </xsl:choose>
  126.       </xsl:with-param>
  127.     </xsl:call-template>
  128.     <xsl:apply-templates/>
  129.   </dt>
  130. </xsl:template>
  131.  
  132. <xsl:template match="glossentry/acronym">
  133. </xsl:template>
  134.  
  135. <xsl:template match="glossentry/abbrev">
  136. </xsl:template>
  137.  
  138. <xsl:template match="glossentry/revhistory">
  139. </xsl:template>
  140.  
  141. <xsl:template match="glossentry/glosssee">
  142.   <xsl:variable name="otherterm" select="@otherterm"/>
  143.   <xsl:variable name="targets" select="//node()[@id=$otherterm]"/>
  144.   <xsl:variable name="target" select="$targets[1]"/>
  145.   <dd>
  146.     <p>
  147.       <xsl:call-template name="gentext.template">
  148.         <xsl:with-param name="context" select="'glossary'"/>
  149.         <xsl:with-param name="name" select="'see'"/>
  150.       </xsl:call-template>
  151.       <xsl:choose>
  152.         <xsl:when test="@otherterm">
  153.           <a href="#{@otherterm}">
  154.             <xsl:apply-templates select="$target" mode="xref"/>
  155.           </a>
  156.         </xsl:when>
  157.         <xsl:otherwise>
  158.           <xsl:apply-templates/>
  159.         </xsl:otherwise>
  160.       </xsl:choose>
  161.       <xsl:text>.</xsl:text>
  162.     </p>
  163.   </dd>
  164. </xsl:template>
  165.  
  166. <xsl:template match="glossentry/glossdef">
  167.   <dd>
  168.     <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/>
  169.     <xsl:if test="glossseealso">
  170.       <p>
  171.         <xsl:call-template name="gentext.template">
  172.           <xsl:with-param name="context" select="'glossary'"/>
  173.           <xsl:with-param name="name" select="'seealso'"/>
  174.         </xsl:call-template>
  175.         <xsl:apply-templates select="glossseealso"/>
  176.       </p>
  177.     </xsl:if>
  178.   </dd>
  179. </xsl:template>
  180.  
  181. <xsl:template match="glossseealso">
  182.   <xsl:variable name="otherterm" select="@otherterm"/>
  183.   <xsl:variable name="targets" select="//node()[@id=$otherterm]"/>
  184.   <xsl:variable name="target" select="$targets[1]"/>
  185.  
  186.   <xsl:choose>
  187.     <xsl:when test="@otherterm">
  188.       <a href="#{@otherterm}">
  189.         <xsl:apply-templates select="$target" mode="xref"/>
  190.       </a>
  191.     </xsl:when>
  192.     <xsl:otherwise>
  193.       <xsl:apply-templates/>
  194.     </xsl:otherwise>
  195.   </xsl:choose>
  196.  
  197.   <xsl:choose>
  198.     <xsl:when test="position() = last()">
  199.       <xsl:text>.</xsl:text>
  200.     </xsl:when>
  201.     <xsl:otherwise>
  202.       <xsl:text>, </xsl:text>
  203.     </xsl:otherwise>
  204.   </xsl:choose>
  205. </xsl:template>
  206.  
  207. <!-- ==================================================================== -->
  208.  
  209. <xsl:template match="glossentry" mode="xref">
  210.   <xsl:apply-templates select="./glossterm[1]" mode="xref"/>
  211. </xsl:template>
  212.  
  213. <xsl:template match="glossterm" mode="xref">
  214.   <xsl:apply-templates/>
  215. </xsl:template>
  216.  
  217. <!-- ==================================================================== -->
  218.  
  219. <!-- Glossary collection -->
  220.  
  221. <xsl:template match="glossary[@role='auto']" priority="2">
  222.   <xsl:variable name="terms" select="//glossterm[not(parent::glossdef)]|//firstterm"/>
  223.   <xsl:variable name="collection" select="document($glossary.collection, .)"/>
  224.  
  225.   <xsl:if test="$glossary.collection = ''">
  226.     <xsl:message>
  227.       <xsl:text>Warning: processing automatic glossary </xsl:text>
  228.       <xsl:text>without a glossary.collection file.</xsl:text>
  229.     </xsl:message>
  230.   </xsl:if>
  231.  
  232.   <div class="{name(.)}">
  233.     <xsl:if test="$generate.id.attributes != 0">
  234.       <xsl:attribute name="id">
  235.         <xsl:call-template name="object.id"/>
  236.       </xsl:attribute>
  237.     </xsl:if>
  238.  
  239.     <xsl:call-template name="glossary.titlepage"/>
  240.  
  241.     <xsl:choose>
  242.       <xsl:when test="glossdiv and $collection//glossdiv">
  243.         <xsl:for-each select="$collection//glossdiv">
  244.           <!-- first see if there are any in this div -->
  245.           <xsl:variable name="exist.test">
  246.             <xsl:for-each select="glossentry">
  247.               <xsl:variable name="cterm" select="glossterm"/>
  248.               <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  249.                 <xsl:value-of select="glossterm"/>
  250.               </xsl:if>
  251.             </xsl:for-each>
  252.           </xsl:variable>
  253.  
  254.           <xsl:if test="$exist.test != ''">
  255.             <xsl:apply-templates select="." mode="auto-glossary">
  256.               <xsl:with-param name="terms" select="$terms"/>
  257.             </xsl:apply-templates>
  258.           </xsl:if>
  259.         </xsl:for-each>
  260.       </xsl:when>
  261.       <xsl:otherwise>
  262.         <dl>
  263.           <xsl:for-each select="$collection//glossentry">
  264.             <xsl:variable name="cterm" select="glossterm"/>
  265.             <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  266.               <xsl:apply-templates select="." mode="auto-glossary"/>
  267.             </xsl:if>
  268.           </xsl:for-each>
  269.         </dl>
  270.       </xsl:otherwise>
  271.     </xsl:choose>
  272.  
  273.     <xsl:call-template name="process.footnotes"/>
  274.   </div>
  275. </xsl:template>
  276.  
  277. <xsl:template match="*" mode="auto-glossary">
  278.   <!-- pop back out to the default mode for most elements -->
  279.   <xsl:apply-templates select="."/>
  280. </xsl:template>
  281.  
  282. <xsl:template match="glossdiv" mode="auto-glossary">
  283.   <xsl:param name="terms" select="."/>
  284.  
  285.   <div class="{name(.)}">
  286.     <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
  287.  
  288.     <dl>
  289.       <xsl:for-each select="glossentry">
  290.         <xsl:variable name="cterm" select="glossterm"/>
  291.         <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
  292.           <xsl:apply-templates select="." mode="auto-glossary"/>
  293.         </xsl:if>
  294.       </xsl:for-each>
  295.     </dl>
  296.   </div>
  297. </xsl:template>
  298.  
  299. <xsl:template match="glossentry" mode="auto-glossary">
  300.   <xsl:apply-templates mode="auto-glossary"/>
  301. </xsl:template>
  302.  
  303. <xsl:template match="glossentry/glossterm[1]" priority="2" mode="auto-glossary">
  304.   <xsl:variable name="id">
  305.     <xsl:text>gl.</xsl:text>
  306.     <xsl:call-template name="object.id">
  307.       <xsl:with-param name="object" select=".."/>
  308.     </xsl:call-template>
  309.   </xsl:variable>
  310.  
  311.   <dt>
  312.     <a name="{$id}"/>
  313.     <xsl:apply-templates/>
  314.   </dt>
  315. </xsl:template>
  316.  
  317. <!-- ==================================================================== -->
  318.  
  319. </xsl:stylesheet>
  320. This resource fork intentionally left blank   ˇˇ